package cn.itsource.basic.basic.controller;

import cn.itsource.basic.basic.domain.dto.LoginDto;
import cn.itsource.basic.basic.service.ILoginService;
import cn.itsource.basic.exception.CustomException;
import cn.itsource.basic.utils.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/login")
public class LoginController {
    @Autowired
    private ILoginService loginService;

    @PostMapping("/account")
    public AjaxResult accountLogin(@RequestBody LoginDto dto){
        try {
            System.out.println(dto);
            return AjaxResult.me().setResultObj(loginService.accountLogin(dto));
        }catch (CustomException e){
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("服务器繁忙，请稍后重试！");
        }
    }

}
